<template>
  <div class="wp-box">
    <!-- 协议解读 -->
    <div class="check-1">
      <p class="check-tit">输出协议解读</p>
      <div v-for="(item, index) in newData" :key="index">
        <p class="check-p">{{ item.Name }}</p>
        <el-checkbox-group v-model="checked" @change="agreementOne">
          <el-checkbox
            class="portraitBox"
            :label="items"
            v-for="(items, indexs) in item.contentList"
            :key="indexs"
            >{{ items.Describe }}
          </el-checkbox>
        </el-checkbox-group>
      </div>
    </div>
  </div>
</template>
  
  <script>
import { defineComponent, toRaw } from "vue";
export default defineComponent({
  name: "",
  components: {},
  data() {
    return {
      ProtocolConfig: [],
      checked: [],
      SubList: [],
      newData: [
        {
          Name: "雷达配置",
          contentList: [
            {
              Id: 1,
              System: "毫米波雷达系统",
              CanId: 0x201,
              Name: "雷达配置",
              Attribute: "RadarState_MaxDistanceCfg",
              Describe: "远距离扫描的最大距离",
              Data: "40 1D 40 00 00 34 00 00",
            },
            {
              Id: 2,
              System: "毫米波雷达系统",
              CanId: 0x201,
              Name: "雷达配置",
              Attribute: "RadarState_OutputTypeCfg",
              Describe: "输出目标类型",
              Data: "40 1D 40 00 00 34 00 00",
            },
            {
              Id: 3,
              System: "毫米波雷达系统",
              CanId: 0x201,
              Name: "雷达配置",
              Attribute: "RadarState_RadarPowerCfg",
              Describe: "发射功率",
              Data: "40 1D 40 00 00 34 00 00",
            },
            {
              Id: 4,
              System: "毫米波雷达系统",
              CanId: 0x201,
              Name: "雷达配置",
              Attribute: "RadarState_MotionRxState",
              Describe: "输入标记状态",
              Data: "40 1D 40 00 00 34 00 00",
            },
          ],
        },
        {
          Name: "目标状态",
          contentList: [
            {
              Id: 5,
              System: "毫米波雷达系统",
              CanId: 0x60a,
              Name: "目标状态",
              Attribute: "Object_NofObjects",
              Describe: "目标数量",
              Data: "07 6F 53 10 00 00 00 00",
            },
            {
              Id: 6,
              System: "毫米波雷达系统",
              CanId: 0x60a,
              Name: "目标状态",
              Attribute: "Object_MeasCounter",
              Describe: "测量周期计数器",
              Data: "07 6F 53 10 00 00 00 00",
            },
          ],
        },
        {
          Name: "目标扩展信息",
          contentList: [
            {
              Id: 7,
              System: "毫米波雷达系统",
              CanId: 0x60d,
              Name: "目标扩展信息",
              Attribute: "Object_ArelLong",
              Describe: "纵向相对加速器",
              Data: "01 7D 0F A0 70 80 19 05",
            },
            {
              Id: 8,
              System: "毫米波雷达系统",
              CanId: 0x60d,
              Name: "目标扩展信息",
              Attribute: "Object_ArelLat",
              Describe: "横向相对加速度",
              Data: "01 7D 0F A0 70 80 19 05",
            },
            {
              Id: 9,
              System: "毫米波雷达系统",
              CanId: 0x60d,
              Name: "目标扩展信息",
              Attribute: "Object_Length",
              Describe: "目标长度",
              Data: "01 7D 0F A0 70 80 19 05",
            },
            {
              Id: 10,
              System: "毫米波雷达系统",
              CanId: 0x60d,
              Name: "目标扩展信息",
              Attribute: "Object_Width",
              Describe: "目标宽度",
              Data: "01 7D 0F A0 70 80 19 05",
            },
          ],
        },

        {
          Name: "目标一般信息",
          contentList: [
            {
              Id: 11,
              System: "毫米波雷达系统",
              CanId: 0x60b,
              Name: "目标一般信息",
              Attribute: "Object_ID",
              Describe: "目标ID",
              Data: "05 4F 9B F5 80 20 01 71",
            },
          ],
        },
      ],
    };
  },
  created() {
    this.Echo();
  },
  methods: {
    // 回显方法
    Echo() {
      this.ProtocolConfig =
        JSON.parse(sessionStorage.getItem("AgreementList")) || [];
      console.log('this.ProtocolConfig',this.ProtocolConfig);
      this.ProtocolConfig.forEach((item) => {
        item.Properties.forEach((items) => {
          this.newData.forEach((i) => {
            i.contentList.forEach((val) => {
              if (val.Attribute == items) {
                this.checked.push(val);
              }
            });
          });
        });
      });
      // console.log(this.checked,'回显');
    },
    agreementOne(data) {
      console.log('??????',data);
      let newId = [];
      data.forEach((item) => {
        newId.push(item.CanId);
      });
      let newArrId = new Set(newId);
      let ArrData = [];
      newArrId.forEach((j) => {
        data.forEach((k) => {
          if (k.CanId == j) {
            ArrData.push({ Id: k.CanId, Properties: [] });
          }
        });
      });
      ArrData.forEach((l, index) => {
        data.forEach((v) => {
          if (v.CanId == l.Id) {
            let newDatas = [];
            v.Data.split(" ").forEach((o) => {
              newDatas.push(Number.parseInt(o, [16]));
            });
            l.Data = newDatas;
            l.Properties.push(v.Attribute);
          }
        });
      });
      // console.log(ArrData);
      let newDataList = ArrData.filter(function (element, index, self) {
        return self.findIndex((el) => el.Id == element.Id) === index;
      });
      console.log('haomibo',newDataList);
      this.SubList = newDataList;
    },
    Sub() {
      console.log('毫米波提交的数据',this.SubList);
      if(this.SubList.length == 0) {
        this.SubList = JSON.parse(sessionStorage.getItem("AgreementList"))
        console.log('this.SubList',this.SubList);
      }
      this.$emit("ok", this.SubList);
    },
  },
});
</script>
  
<style lang="less" scoped>
/deep/.el-icon {
  display: none;
}
/deep/.el-tree-node__label {
  font-size: 18px;
}
/deep/.el-tree-node__content {
  padding: 4px 0;
}
.tree-1 {
  margin-left: 20px;
  margin-top: 30px;
  padding-bottom: 20px;
}
/deep/.el-checkbox__input.is-checked + .el-checkbox__label {
  color: #1b1b1d;
}
.check-1 {
  margin-left: 20px;
  margin-top: 30px;
}
.check-p {
  color: #1b1b1d;
  padding-left: 14px;
  font-size: 18px;
}
.check-tit {
  color: #1b1b1d;
  margin-bottom: 8px;
  font-size: 18px;
}
.portraitBox {
  height: 32px;
  padding-left: 26px;
  padding-right: 80px;
}
</style>